<?php

namespace App\Services\Store;

use App\Models\Store\Store;
use App\Models\Store\CheckIn;
use App\Services\Com\UtilService;
use App\Services\Com\LogService;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class StoreService
{
    public static function checkDistance($user_l1 = '', $user_l2 = '', $s_l1 = '', $s_l2 = ''){
        // $http = new \GuzzleHttp\Client;
        // $url = env('A_MAP_API_URL').'/distance?origins='.$user_l1.','.$user_l2.'&destination='.$s_l1.','.$s_l2.'&type=0&output=json&key='.env('A_MAP_API_WEB_KEY');
        try {
            // $response = $http->get($url);
            // $result = json_decode((string)$response->getBody(), true);
            $distance = UtilService::distance($user_l1, $user_l2, $s_l1, $s_l2);
            if( $distance != null && $distance <= 100 ){
                return true;
            }
        }
        catch (\Exception $e) {
            LogService::error('checkDistance error: '.$e->getMessage());
            return false;
        }
        
        return false;
    }


}